import 'package:flutter/material.dart';

class LikeAnimationWidget extends StatefulWidget{
  @override
  _LikeAnimationWidgetState createState() {
    // TODO: implement createState
    return _LikeAnimationWidgetState();
  }
}
class _LikeAnimationWidgetState extends State<LikeAnimationWidget> with TickerProviderStateMixin{
  late AnimationController controller;
  late CurvedAnimation curve;
  late Animation animationSize;
  double size=25.0;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller=AnimationController(vsync: this,duration: Duration(milliseconds: 150));
    curve=CurvedAnimation(parent: controller,curve: Curves.easeInCirc);
    animationSize=Tween(begin: 40.0,end: 35.0,).animate(controller);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(
      child: LikeAnimation(
        controller: controller,
        list: [
          animationSize,
        ],
      ),
    );
  }
}

class LikeAnimation extends AnimatedWidget implements StatefulWidget{
  AnimationController controller;
  List<Animation> list;
  bool color=false;
  LikeAnimation({
    required this.controller, required this.list
  }):super(listenable:controller);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GestureDetector(
      child: Icon(
        Icons.favorite,
        size: list[0].value,
        color: color?Colors.red:Colors.grey,
      ),
      onTapDown: (DragDownDetails){
        controller.forward();
      },
      onTapUp: (DragDownDetails){
        if(!color){
          new Future.delayed(Duration(milliseconds: 100),(){
            controller.reverse();
            color=true;
          });
          return;
        }
        new Future.delayed(Duration(milliseconds: 100),(){
          controller.reverse();
          color=false;
        });
        return;
      },
    );
  }
}
